home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / WizardResourceBundle.java < prev    next >
Text File  |  1998-09-08  |  3KB  |  151 lines

  1. package com.symantec.itools.frameworks.wizard;
  2.  
  3.  
  4. import java.util.ResourceBundle;
  5. import java.util.Enumeration;
  6. import java.util.Hashtable;
  7. import java.util.Locale;
  8. import java.util.MissingResourceException;
  9.  
  10.  
  11. /**
  12.  * @author Symantec Internet Tools Division
  13.  * @version 1.0
  14.  * @since VCafe 3.0
  15.  */
  16.  
  17. public class WizardResourceBundle extends ResourceBundle
  18. {
  19.  
  20.     /**
  21.      * @since VCafe 3.0
  22.      */
  23.     ResourceBundle resourceBundle;
  24.     public WizardResourceBundle(String baseName, Locale locale)
  25.     {
  26.         try
  27.         {
  28.             resourceBundle = ResourceBundle.getBundle(baseName, locale);
  29.         }
  30.         catch (MissingResourceException mre)
  31.         {
  32.             resourceBundle = null;
  33.             System.err.println("Resource bundle " + baseName + " not found");
  34.         }
  35.     }
  36.  
  37.     /**
  38.      * @param key TODO
  39.      * @since VCafe 3.0
  40.      */
  41.  
  42.     public String getResourceString(String key)
  43.     {
  44.         String str = null;
  45.         try
  46.         {
  47.             str = resourceBundle.getString(key);
  48.         }
  49.         catch (MissingResourceException mre)
  50.         {
  51.             //str = "<<unknown>>";
  52.             System.err.println("Resource key " + key + " not found");
  53.         }
  54.         return str;
  55.     }
  56.  
  57.     /**
  58.      * @param key TODO
  59.      * @since VCafe 3.0
  60.      */
  61.  
  62.     public final Object handleGetObject(String key)
  63.     {
  64.         // lazily load the lookup hashtable.
  65.         if (lookup == null)
  66.         {
  67.             loadLookup();
  68.         }
  69.  
  70.         return lookup.get(key); // this class ignores locales
  71.     }
  72.  
  73.     /**
  74.      * @since VCafe 3.0
  75.      */
  76.  
  77.     public Enumeration getKeys()
  78.     {
  79.         // lazily load the lookup hashtable.
  80.         if (lookup == null)
  81.         {
  82.             loadLookup();
  83.         }
  84.         Enumeration result = null;
  85.         if (parent != null)
  86.         {
  87.             Hashtable temp = new Hashtable();
  88.             for (Enumeration parentKeys = parent.getKeys() ;
  89.              parentKeys.hasMoreElements() ; /* nothing */)
  90.             {
  91.                 temp.put(parentKeys.nextElement(), this);
  92.             }
  93.             for (Enumeration thisKeys = lookup.keys();
  94.              thisKeys.hasMoreElements() ; /* nothing */)
  95.             {
  96.                 temp.put(thisKeys.nextElement(), this);
  97.             }
  98.             result = temp.keys();
  99.         }
  100.         else
  101.         {
  102.             result = lookup.keys();
  103.         }
  104.         return result;
  105.     }
  106.  
  107.     /**
  108.      * @since VCafe 3.0
  109.      */
  110.  
  111.     private void loadLookup() {
  112.         Object[][] contents = getContents();
  113.         if (contents == null)
  114.         {
  115.             lookup = new Hashtable();
  116.         }
  117.         else
  118.         {
  119.             int len = contents.length;
  120.             if (len > 0)
  121.                 lookup = new Hashtable(len);
  122.             else
  123.                 lookup = new Hashtable();
  124.             for (int i = 0; i < len; ++i)
  125.             {
  126.                 lookup.put(contents[i][0],contents[i][1]);
  127.             }
  128.         }
  129.     }
  130.  
  131.    /**
  132.     * @since VCafe 3.0
  133.     */
  134.  
  135.    private Hashtable lookup = null;
  136.  
  137.    /**
  138.     * @since VCafe 3.0
  139.     */
  140.  
  141.    public Object[][] getContents()
  142.    {
  143.        return contents;
  144.    }
  145.  
  146.    /**
  147.     * @since VCafe 3.0
  148.     */
  149.  
  150.    static final Object[][] contents = {};
  151. }